import re
from urllib.parse import urlparse, urlunparse


def merge_relative_url(base: str, relative: str) -> str:
    base_parsed = urlparse(base)
    return urlunparse((base_parsed.scheme, base_parsed.netloc, relative, "", "", ""))


def is_same_chapter(current_url: str, next_url: str) -> bool:
    def normalize(u):
        return re.sub(r"_\d+(?=\.html)", "", u)

    return normalize(current_url) == normalize(next_url)
